package com.zhongkun.datahome.web.rest;

import com.zhongkun.datahome.common.annotation.Log;
import com.zhongkun.datahome.common.core.controller.BaseController;
import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.common.enums.BusinessType;
import com.zhongkun.datahome.service.domain.DecorationStandard;
import com.zhongkun.datahome.service.req.IdsBody;
import com.zhongkun.datahome.service.req.cmd.standard.DecorationStandardCmd;
import com.zhongkun.datahome.service.req.qry.standard.DecorationStandardQry;
import com.zhongkun.datahome.service.res.PageVo;
import com.zhongkun.datahome.service.res.standard.DecorationStandardDetailVo;
import com.zhongkun.datahome.service.service.IDecorationStandardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 装标Controller
 * 
 * @author ruoyi
 * @date 2025-04-14
 */
@Api("装标管理")
@RestController
@RequestMapping("/core/standard")
public class DecorationStandardController extends BaseController {
    @Resource
    private IDecorationStandardService decorationStandardService;


    @ApiOperation("查询装标列表")
    @PreAuthorize("@ss.hasPermi('core:standard:page')")
    @GetMapping("/page")
    public R<PageVo<DecorationStandard>> page(DecorationStandardQry qry) {
        return R.ok(decorationStandardService.page(qry));
    }

    @ApiOperation("查询装标详细信息")
    @PreAuthorize("@ss.hasPermi('core:standard:query')")
    @GetMapping(value = "/{id}")
    public R<DecorationStandardDetailVo> getInfo(@PathVariable("id") Long id) {
        return R.ok(decorationStandardService.getInfo(id));
    }

    @ApiOperation("新增装标")
    @PreAuthorize("@ss.hasPermi('core:standard:add')")
    @Log(title = "装标", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Long> add(@RequestBody DecorationStandardCmd cmd) {
        return R.ok(decorationStandardService.add(cmd));
    }


    @ApiOperation("修改装标")
    @PreAuthorize("@ss.hasPermi('core:standard:edit')")
    @Log(title = "装标", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody DecorationStandardCmd cmd) {
        decorationStandardService.update(cmd);
        return R.ok();
    }

    @ApiOperation("删除装标")
    @PreAuthorize("@ss.hasPermi('core:standard:remove')")
    @Log(title = "装标", businessType = BusinessType.DELETE)
	@DeleteMapping
    public R<Void> remove(@RequestBody IdsBody idsBody) {
        decorationStandardService.remove(idsBody.getIds());
        return R.ok();
    }

    @ApiOperation("导入装标清单")
    @PreAuthorize("@ss.hasPermi('core:standard:import')")
    @Log(title = "装标", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public R<Void> importStandards(@RequestParam("standardName") String standardName,
                               @RequestParam("file") MultipartFile file) {
        decorationStandardService.importStandardsFromExcel(standardName, file);
        return R.ok();
    }
}
